package rxjava.application.com.androidmyp.Home;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rxjava.application.com.androidmyp.R;
import rxjava.application.com.androidmyp.View.CircleAnimation;

public class HomeActivity extends AppCompatActivity implements CircleAnimation.CircleClickListener {


    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.mImageView)
    Button mImageView;
    @Bind(R.id.alpha)
    Button alpha;
    @Bind(R.id.rote)
    Button rote;
    @Bind(R.id.scale)
    Button scale;
    @Bind(R.id.btn1)
    Button btn1;
    @Bind(R.id.fab)
    FloatingActionButton fab;
    @Bind(R.id.navigationView)
    NavigationView navigationView;
    @Bind(R.id.drawerlayout)
    DrawerLayout drawerlayout;
    CircleAnimation circleAnimation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        ButterKnife.bind(this);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("主页");
        toolbar.setNavigationIcon(android.R.drawable.ic_menu_slideshow);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayShowHomeEnabled(true);
        ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, drawerlayout, toolbar, android.R.drawable.ic_menu_more,
                android.R.drawable.ic_media_next);
        mDrawerToggle.syncState();
        drawerlayout.setDrawerListener(mDrawerToggle);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                Toast.makeText(HomeActivity.this, item.getTitle().toString(), Toast.LENGTH_SHORT).show();
                drawerlayout.closeDrawers();
                return false;
            }
        });
        initAnimation();
    }

    private void initAnimation() {
        List<View> list = new ArrayList<View>();
        list.add(btn1);
        list.add(mImageView);
        list.add(rote);
        list.add(scale);
        list.add(alpha);
        circleAnimation = new CircleAnimation(300, list, this);
    }

    @OnClick({R.id.mImageView, R.id.alpha, R.id.rote, R.id.scale, R.id.fab})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.mImageView:
                Animation animation = AnimationUtils.loadAnimation(this, R.anim.traslate_one);
                mImageView.startAnimation(animation);
                break;
            case R.id.alpha:
                Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha_one);
                HomeActivity.this.alpha.startAnimation(alpha);
                break;
            case R.id.rote:
                Animation roate = AnimationUtils.loadAnimation(this, R.anim.roate);
                rote.startAnimation(roate);
                break;
            case R.id.scale:
                Dialog dialog = new AlertDialog.Builder(this)
                        .setTitle("我是照片是的")
                        .setPositiveButton("确认", null)
                        .setNegativeButton("取消", null)
                        .create();
                Window window= dialog.getWindow();
                window.setWindowAnimations(R.style.mystyle);
                dialog.show();
                break;
            case R.id.fab:
                circleAnimation.start();
                break;
        }
    }

    @Override
    public void onClick(boolean isOpen) {

    }
}
